﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing.Drawing2D;
using System.Drawing;



using System.Runtime.Serialization;




namespace HAVTKPack
{


    /// <summary>
    /// 用于存储等置线的一些设置
    /// </summary>
    [Serializable]
    public class ContourSetup
    {

        #region 构造函数

        public ContourSetup()
        {


            this._displayContours = new Dictionary<double, Color>();



            this._contourLineProperty = new ContourLineProperty();

            this._scalarBar = new ContourScalarBar();

            this._tagging = new ContourTagging();

        }

        #endregion


        #region 字段属性 


        bool _isContours = true;
        /// <summary>
        /// 标记是否进行  Contour
        /// </summary>
        public bool IsContours
        {
            get { return _isContours; }
            //set { _isContours = value; }
        }



        CONTOURMODE _contourMode = CONTOURMODE.LayerContours;
        /// <summary>
        /// contour的类型   Layer还是Grid
        /// </summary>
        public CONTOURMODE ContourMode
        {
            get { return _contourMode; }
            //set { _contourMode = value; }
        }






        int _numContours = 0;
        /// <summary>
        /// 等值线的条数
        /// </summary>
        public int NumContours
        {
            get { return _numContours; }
            //set { _numContours = value; }
        }



        /// <summary>
        /// 等值线值，颜色（0-255）  集合
        /// </summary>
        Dictionary<double, Color> _displayContours;
        /// <summary>
        /// 等值线值，颜色（0-255）  集合
        /// </summary>
        public Dictionary<double, Color> DisplayContours
        {
            get { return _displayContours; }
           
        }




        ContourLineProperty _contourLineProperty;

        public ContourLineProperty ContourLineProperty
        {
            get { return _contourLineProperty; }
            //set { _contourLineProperty = value; }
        }





        ContourScalarBar _scalarBar;

        public ContourScalarBar ScalarBar
        {
            get { return _scalarBar; }
            //set { _scalarBar = value; }
        }



        ContourTagging _tagging;

        public ContourTagging Tagging
        {
            get { return _tagging; }
            //set { _tagging = value; }
        }





        #endregion




        #region 共有方法

        public void UpdateContourSetup(ContourSetup contourSetup)
        {
            if (contourSetup != null)
            {

                this._isContours = contourSetup._isContours;

                this._contourMode = contourSetup._contourMode;


                this.ResetContours(contourSetup._displayContours);


                if (this._contourLineProperty !=null )
                {
                    this._contourLineProperty.UpdateContourLineProperty(contourSetup ._contourLineProperty );
                }
                else
                {
                    this._contourLineProperty = contourSetup._contourLineProperty;     
                }

                if (this._scalarBar != null)
                {
                    this._scalarBar.UpdateContourScalarBar(contourSetup._scalarBar);
                }
                else 
                { 
                    this._scalarBar = contourSetup._scalarBar;
                }


                if (this._tagging != null)
                {
                    this._tagging.UpdateContourTagging(contourSetup._tagging);
                }
                else
                {
                    this._tagging = contourSetup._tagging;
                }
                this._numContours = contourSetup.NumContours;

            }

        }

        public void ResetContours(Dictionary<double, Color> contourLines) 
        {
            this._displayContours.Clear();

            if (contourLines != null)
            {
                foreach (KeyValuePair<double, Color> item in contourLines)
                {
                    this._displayContours.Add(item.Key, item.Value);

                }
            }

            this._numContours = this._displayContours.Count;

            //this.ScalarRangeMin = scalarMin;
            //this.ScalarRangeMax = scalarMax;

        }


        public void UpdateVisibility(bool isContour)
        {
            this._isContours = isContour;

        }

        public void UpdateContourModel(CONTOURMODE contourMode)
        {
            this._contourMode = contourMode;
        
        }

        public void UpdateContourLineValue(Dictionary<double, Color> contourLines)
        {
            this.ResetContours(contourLines);
        
        }

        public void UpdateScalarBar(ContourScalarBar scalarBar)
        {
           

            if (this._scalarBar != null)
            {
                this._scalarBar.UpdateContourScalarBar(scalarBar);
            }
            else
            {
                this._scalarBar = scalarBar;
            }



        }

        public void UpdateTagging(ContourTagging  tagging )
        {

          


            if (this._tagging != null)
            {
                this._tagging.UpdateContourTagging(tagging);
            }
            else
            {
                this._tagging = tagging;
            }
        }

        public void UpdateContourLineProperty(ContourLineProperty  contourLineProperty)
        {

            if (this._contourLineProperty != null)
            {
                this._contourLineProperty.UpdateContourLineProperty(contourLineProperty);
            }
            else
            {
                this._contourLineProperty = contourLineProperty;
            }

           
        }



        #endregion


        #region 内部方法


        #endregion



        [OnDeserializing]
        public void OnDeserializing(StreamingContext context)
        {

            if (_scalarBar ==null )
            {
                _scalarBar = new ContourScalarBar();
            }


            if (_tagging ==null )
            {
                _tagging = new ContourTagging();
            }

            if (_contourLineProperty ==null )
            {
                _contourLineProperty = new ContourLineProperty();
            }



        //    if (_cpostUIParameter == null)
        //    {
        //        _cpostUIParameter = new CpostUIParameter();
       //    }

        //    if (_vDataResult == null)
        //    {

        //        _vDataResult = new VDataResult("VISIB");

        //    }

      

        }


    }
}
